/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.za.cput.hotelbooking.services.crud.impl;

import ac.za.cput.hotelbooking.model.Guest;
import ac.za.cput.hotelbooking.model.Hotel;
import ac.za.cput.hotelbooking.repository.GenericDAO;
import ac.za.cput.hotelbooking.services.crud.HotelCrudService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Andisiwe
 */
@Service("HotelCrudService")
@Transactional
public class HotelCrudServiceImpl implements HotelCrudService {
    
     @Autowired
    private GenericDAO<Hotel> dao;
     
       public final void setDao(final GenericDAO<Hotel> daoToSet) {
        this.dao = daoToSet;
        this.dao.setClazz(Hotel.class);
    }
       
    @Override
    public Hotel findById(Long id) {
        setDao(dao);
        return dao.findById(id);
    }
    
    @Override
    public List<Hotel> findAll() {
        setDao(dao);
        return dao.findAll();
    }

    @Override
    public void persist(Hotel entity) {
       setDao(dao);
       dao.persist(entity);
       
    }

    @Override
    public void merge(Hotel entity) {
          setDao(dao);
        dao.merge(entity);
    }

    @Override
    public void remove(Hotel entity) {
        setDao(dao);
       dao.remove(entity);
    }

    @Override
    public void removeById(Long entityId) {
        setDao(dao);
        Hotel h = dao.findById(entityId);
        dao.remove(h);throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Hotel> findInRange(int firstResult, int maxResults) {
        setDao(dao);
        return dao.findInRange(firstResult, maxResults);
    }

    @Override
    public long count() {
        setDao(dao);
        return dao.count();
    }

    @Override
    public Hotel getByPropertyName(String name, String value) {
        setDao(dao);
        return dao.getByPropertyName(name, value);
    }

    @Override
    public List<Hotel> getEntitiesByProperName(String name, String value) {
        setDao(dao);
        return dao.getEntitiesByProperName(name, value);
    }
}
